package com.yehongyu.mytools.ui.applet;

import java.applet.Applet;
import java.awt.Button;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TextFieldApplet extends Applet implements ActionListener {

	/** 序列ID */
	private static final long serialVersionUID = 1L;

	Button b1 = new Button("Get Text"), b2 = new Button("Set Text");
	TextField t = new TextField("Starting text", 30);
	String s = new String();

	public void init() {
		add(b1);
		add(b2);
		add(t);
		b1.addActionListener(this);
		b2.addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource().equals(b1)) {
			getAppletContext().showStatus(t.getText());
			s = t.getSelectedText();
			if (s.length() == 0)
				s = t.getText();
			t.setEditable(true);
		} else if (e.getSource().equals(b2)) {
			t.setText("Inserted by Button 2: " + s);
			t.setEditable(false);
		} else {
			System.out.println("Object is [" + e.getSource()
					+ "],Unknown Action!");
		}
	}

}
